package com.ruoyi.web.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.admin.domain.TdmCfda;
import com.ruoyi.web.admin.service.ITdmCfdaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * CFDA数据库Controller
 * 
 * @author ly
 * @date 2022-03-10
 */
@RestController
@RequestMapping("/admin/cfda")
public class TdmCfdaController extends BaseController
{
    @Autowired
    private ITdmCfdaService tdmCfdaService;

    /**
     * 查询CFDA数据库列表
     */
//    @PreAuthorize("@ss.hasPermi('admin:cfda:list')")
    @GetMapping("/list")
    public TableDataInfo list(TdmCfda tdmCfda)
    {
        startPage();
        List<TdmCfda> list = tdmCfdaService.selectTdmCfdaList(tdmCfda);
        return getDataTable(list);
    }

    /**
     * 导出CFDA数据库列表
     */
//    @PreAuthorize("@ss.hasPermi('admin:cfda:export')")
    @Log(title = "CFDA数据库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdmCfda tdmCfda)
    {
        List<TdmCfda> list = tdmCfdaService.selectTdmCfdaList(tdmCfda);
        ExcelUtil<TdmCfda> util = new ExcelUtil<TdmCfda>(TdmCfda.class);
        util.exportExcel(response, list, "CFDA数据库数据");
    }

    /**
     * 获取CFDA数据库详细信息
     */
//    @PreAuthorize("@ss.hasPermi('admin:cfda:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tdmCfdaService.selectTdmCfdaById(id));
    }

    /**
     * 新增CFDA数据库
     */
//    @PreAuthorize("@ss.hasPermi('admin:cfda:add')")
    @Log(title = "CFDA数据库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdmCfda tdmCfda)
    {
        return toAjax(tdmCfdaService.insertTdmCfda(tdmCfda));
    }

    /**
     * 修改CFDA数据库
     */
//    @PreAuthorize("@ss.hasPermi('admin:cfda:edit')")
    @Log(title = "CFDA数据库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdmCfda tdmCfda)
    {
        return toAjax(tdmCfdaService.updateTdmCfda(tdmCfda));
    }

    /**
     * 删除CFDA数据库
     */
//    @PreAuthorize("@ss.hasPermi('admin:cfda:remove')")
    @Log(title = "CFDA数据库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tdmCfdaService.deleteTdmCfdaByIds(ids));
    }
}
